package util

import "time"

func IsLeapYear(year int) bool {
	return year%4 == 0 && (year%100 != 0 || year%400 == 0)
}

func DaysInMonth(year int, month time.Month) int {
	if month == time.February && IsLeapYear(year) {
		return 29
	}
	// 使用time包内置的逻辑来获取月份天数，这是最准确且简洁的方法
	// 当指定的日期为下个月的0号时，它会返回上个月的最后一天，从而间接获取到该月的天数。
	return time.Date(year, month+1, 0, 0, 0, 0, 0, time.UTC).Day()
}

func IsWeekend(date time.Time) bool {
	weekday := date.Weekday()
	return weekday == time.Saturday || weekday == time.Sunday
}

var WeekdayMap = map[time.Weekday]string{
	time.Sunday:    "周日",
	time.Monday:    "周一",
	time.Tuesday:   "周二",
	time.Wednesday: "周三",
	time.Thursday:  "周四",
	time.Friday:    "周五",
	time.Saturday:  "周六",
}
